//
//  MessageCell.swift
//  SBSafetyApp
//
//  Created by Lina on 2022/12/29.
//

import Foundation
import UIKit

public enum MsgItemType: String {
    case notify = "1"
    case notion = "2"
    case setting = "3"
}

class MsgItemModal: NSObject {
    var type: MsgItemType = .notify

    init(type: MsgItemType) {
        self.type = type
    }
}

class MessageCell: UITableViewCell {
    let titleL = UILabel()
    let contentL = UILabel()
    let dateL = UILabel()

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: .default, reuseIdentifier: reuseIdentifier)
        selectionStyle = .none
        setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func reload(withModal modal: MsgItemModal) {
        switch modal.type {
        case .notify:
            iconIV.image = UIImage(named: "ic_msg_notify")
            titleL.text = "通知"
            contentL.text = "点击查看通知"
            dateL.text = ""
            break
        case .notion:
            iconIV.image = UIImage(named: "ic_msg_notion")
            titleL.text = "公告"
            contentL.text = "点击查看公告"
            dateL.text = ""
            break
        case .setting:
            iconIV.image = UIImage(named: "ic_msg_setting")
            titleL.text = "系统消息"
            contentL.text = "点击查看系统消息"
            dateL.text = ""
            break
        }
    }
    
    func setupUI() {
        iconIV.image = UIImage()
        iconIV.contentMode = .center
        addSubview(iconIV)
        iconIV.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.left.equalToSuperview().offset(10)
            make.width.height.equalTo(45)
        }
        
        titleL.textColor = .hex("#333333")
        titleL.font = .systemFont(ofSize: 17)
        addSubview(titleL)
        titleL.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(14)
            make.left.equalTo(iconIV.snp.right).offset(16)
            make.right.equalToSuperview().offset(-100)
        }
        
        contentL.font = .systemFont(ofSize: 15)
        contentL.textColor = .hex("#999999")
        addSubview(contentL)
        contentL.snp.makeConstraints { make in
            make.top.equalTo(titleL.snp.bottom).offset(8)
            make.left.equalTo(titleL.snp.left)
            make.right.equalTo(titleL.snp.right)
        }
        
        dateL.textColor = .hex("#BDBDBD")
        dateL.font = .systemFont(ofSize: 14)
        dateL.textAlignment = .right
        addSubview(dateL)
        dateL.snp.makeConstraints { make in
            make.centerY.equalTo(titleL.snp.centerY)
            make.left.equalTo(titleL.snp.left)
            make.right.equalToSuperview().offset(-10)
        }
        
        addSubview(line)
        line.snp.makeConstraints { (make) -> Void in
            make.bottom.equalToSuperview()
            make.left.equalTo(contentL.snp.left)
            make.right.equalTo(contentL.snp.right)
            make.height.equalTo(0.5)
        }
    }
    
    override func setHighlighted(_ highlighted: Bool, animated: Bool) {
        super.setHighlighted(highlighted, animated: animated)
        if highlighted {
            backgroundColor = .hex("#ECECEC")
        } else {
            backgroundColor = .white
        }
    }
    lazy var iconIV: UIImageView = {
        let iv = UIImageView()
        return iv
    }()
    
//    lazy var arrowIV: UIImageView = {
//        let iv = UIImageView(image: UIImage(systemName: "chevron.right"))
//        iv.tintColor = .hex("#A5A5A5")
//        iv.contentMode = .scaleAspectFit
//        return iv
//    }()
    
    lazy var line: UIView = {
        let li = UIView()
        li.backgroundColor = .hex("#F3F3F3")
        return li
    }()
}


